/**
 * @file    If_rtc.c
 * @brief   RTC接口
 * @author  Liuwei
 * @version 1.0.1
 * @date    2023-04-19
 * 
 * @copyright Copyright (c) 2023 JBD-Energy Storage Technology Co. LTD
 * 
 * @par 修改日志:
 * <table>
 * <tr><th>Date       <th>Version   <th>Author   <th>Description
 * <tr><td>2023-04-19 <td>1.0.1     <td>Liuwei   <td>首次创建
 * </table>
 */

/* includes ------------------------------------------------------------------*/
#include "If_rtc.h"
#include "drv_rtc.h"
#include "dev_rtc.h"
#include "FreeRTOS.h"
#include "semphr.h"

/* macro/define --------------------------------------------------------------*/

/* typedef -------------------------------------------------------------------*/

/* local functions -----------------------------------------------------------*/

/* static variables ----------------------------------------------------------*/
static SemaphoreHandle_t xRtcSemaphore = NULL;
/* global variables ----------------------------------------------------------*/

/** ------------------------------------------------------------------------- *
  *                             Global function
 ** ------------------------------------------------------------------------- */
/**
 * @brief rtc驱动接口
 */
void If_rtc_init(rtc_data_type rtc_init_time)
{
  //  drv_rtc_init(rtc_init_time);
	xRtcSemaphore = xSemaphoreCreateMutex();
	
    dev_rtc_init(rtc_init_time);
}

/**
 * @brief  RTC接口-读取日期和时间
 * @param  rtc_data : 读取值
 * @return uint8_t : FALSE : 读取失败  TRUE:读取成功
 */
uint8_t If_rtc_read_time(rtc_data_type *rtc_data)
{
	uint8_t ret = 0;
	
	xSemaphoreTake(xRtcSemaphore, 100 );
	
	ret = dev_rtc_read_date_time(rtc_data);
	
	xSemaphoreGive(xRtcSemaphore);
	
    return ret;
}

/**
 * @brief  RTC接口-设置日期和时间
 * @param  rtc_data
 * @return uint8_t 
 */
uint8_t If_rtc_set_time(rtc_data_type set_data)
{
	xSemaphoreTake(xRtcSemaphore, 100 );
	
    dev_rtc_set_date_time(set_data);
	
	xSemaphoreGive(xRtcSemaphore);
	
	return TRUE;
}
/** ------------------------------------------------------------------------- *
  *                              Local function
 ** ------------------------------------------------------------------------- */
 
/********** Copyright (c) 2023 JBD-Energy Storage Technology Co. LTD *********/


